home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / dynConnectToTime.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.1 KB  |  140 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  9 June 1998
  22. // Author:         js
  23. //
  24. //
  25. //  Procedure Name:
  26. //      dynConnectToTime
  27. //
  28. //  Description:
  29. //
  30. //      For each selected particle or emitter object, if that object's
  31. //      current time attribute has no incoming connection,
  32. //      this action makes a connection from time1.outTime.
  33. //      This action is useful when you have duplicated a particle or emitter
  34. //      object without duplicating connections, or in some other
  35. //      way broken the object's input to current time,
  36. //      and you want to re-establish the default input from time1.
  37. //
  38. //
  39. //  Input Arguments:
  40. //      None.
  41. //
  42. //  Return Value:
  43. //      None.
  44. //
  45.  
  46.  
  47. proc connectObjectToTime( string $objName )
  48. //
  49. // Connect the object's currentTime attribute to time1.
  50. // Objects must have a "current time" attribute.
  51. {
  52.         // Is there a connection into currentTime?
  53.         // Get list of connected plugs, see if
  54.         // node name + "currentTime" is in the list.
  55.         //
  56.         string $currTimePlug = $objName + ".currentTime";
  57.  
  58.         string $conn[] = `listConnections -p true -c true $objName`;
  59.  
  60.         int $i;
  61.         int $connectionExists = 0;
  62.         string $connectedTo = "";
  63.         for ( $i= 0; $i < size($conn); $i++)
  64.         {
  65.             // If one of the connected plugs is the current time
  66.             // plug, then a connection exists and we are not
  67.             // supposed to make one.
  68.             //
  69.             if ($conn[ $i ] == $currTimePlug)
  70.             {
  71.                 $connectionExists = 1;
  72.                 $connectedTo = $conn[$i + 1];
  73.                 break;
  74.             }
  75.         }
  76.         
  77.         // If no connection into currentTime was found, make one now
  78.         //
  79.         if ($connectionExists == 0)
  80.         {
  81.             string $cmd = "connectAttr time1.outTime " + $currTimePlug;
  82.             evalEcho $cmd;
  83.         }
  84.         else
  85.         {
  86.             warning($objName + ".currentTime is already connected to " + $connectedTo + ".");
  87.             if ($connectedTo != "time1.outTime")
  88.             {
  89.                 warning("Please break this connection, and try to connect to time1.outTime again.");
  90.             }
  91.         }
  92. }
  93.  
  94.  
  95.  
  96. global proc dynConnectToTime() 
  97. //
  98. //  Get the list of selected objects, get all particle shapes or emitters which are 
  99. //  selected or are children of selected transforms, and call connectObjectToTime
  100. //  to make the connection for each.
  101. {
  102.     // Get the full selection list.
  103.     //
  104.     string $list[] = `ls -sl`;
  105.     int $i;
  106.     for ($i = 0; $i < size($list); $i++)
  107.     {
  108.         // if this is a particle shape or emitter, make the connection
  109.         //
  110.         if ( (`nodeType $list[$i]` == "particle") ||
  111.              (`nodeType $list[$i]` == "fluidEmitter")  ||
  112.              (`nodeType $list[$i]` == "pointEmitter") )
  113.         {
  114.             connectObjectToTime( $list[$i] );        
  115.         }
  116.         else
  117.         {
  118.             // Otherwise, walk through its children.
  119.             // Add to list any particle shapes we find.
  120.             //    
  121.             string $childList[] = `listRelatives -s $list[$i]`;
  122.             int $j;
  123.             for ($j = 0; $j < size($childList); $j++)
  124.             {
  125.                 if ((`nodeType $childList[$j]` == "particle") ||
  126.                     (`nodeType $childList[$j]` == "fluidEmitter") ||
  127.                     (`nodeType $childList[$j]` == "pointEmitter"))
  128.                 {
  129.                     connectObjectToTime( $childList[$j] );        
  130.                   }
  131.                 else
  132.                 {
  133.                     warning($childList[$j] + " is not a particle or emitter; only particles and emitters can be connected to currentTime");
  134.                 }
  135.             }
  136.         }
  137.     }
  138. }
  139.  
  140.